package com.key.base.service.serviceImp;

import org.hibernate.Query;
import org.hibernate.Session;

import com.key.base.service.IBaseService;
import com.key.util.HibernateUtil;

public class BaseServiceImp implements IBaseService {
	/**
	 * 删除所有选中的对象
	 * 
	 * @param className
	 * @param ids
	 * @throws Exception
	 */
	public void deleteAllObj(String className, String[] ids) throws Exception {
		Session session = HibernateUtil.getSessionFactory().openSession();
		try {
			StringBuffer queryHQL = new StringBuffer();
			session.beginTransaction();
			for (int i = 0; i < ids.length; i++) {
				String id = ids[i];
				String hql = "delete from " + className + " where id='" + id
						+ "'";
				System.out.println(hql);
				Query query = session.createQuery(hql);
				System.out.println(query.executeUpdate());
			}
			session.getTransaction().commit();
		} catch (Exception e) {
			session.getTransaction().rollback();
			throw e;
		} finally {
			session.flush();
			session.close();
		}
	}
}
